
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class QueryServletGet
 */
public class QueryServletPost extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public QueryServletPost() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html; charset=euc-kr");
		request.setCharacterEncoding("euc-kr");

		PrintWriter out;
		out = response.getWriter();

		String name = request.getParameter("buyername");
		String addr = request.getParameter("buyeraddr");
		String item[] = request.getParameterValues("buyeritem");

		out.println("<html><body><font coler=red><h2>입력 결과</h2></font><hr/>");
		out.println("이름은 " + name + "이고 주소는 " + addr + "입니다.");
		
		if(item == null){
			out.println("<br>선택하시 상품이 없네요...");
		} else{
			out.println("<pre>선택하신 상품은");
			for(int i = 0; i < item.length; i++){
				out.print(item[i]);
			}
			out.println("\n입니다</pre><br/>");
		}
		
		String getquery = request.getQueryString();
		
		out.println("<br>Get방식으로 전달된 전체 Query : " + getquery);
		out.println("</body></html>");
		
		out.close();
	}

}
